<!DOCTYPE html>
<html>
<head>
	<title>点餐后台管理</title>
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.5/themes/default/easyui.css"></link>
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.5/themes/icon.css"></link>
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.5/demo/demo.css"></link>
	<script language="JavaScript"  type="text/javascript" src="js/jquery-easyui-1.5/jquery.min.js"></script>
	<script language="JavaScript"  type="text/javascript" src="js/jquery-easyui-1.5/jquery.easyui.min.js"></script>
	<script language="JavaScript"  type="text/javascript" src="js/blockUI.js"></script>
	
	<script type="text/javascript">
	/*<![CDATA[*/
           
	var gwidth;
	var gheight; 
	var area;
	var gareaid;
	var gw;
	var gh;
	
	var gshow=20;
	function closetab(title)
	{
		var is = $('#tt').tabs("exists",title);
	    
	    if(is==true)
	    	 var is = $('#tt').tabs("close",title);
	}
	           
	function showmsg(title,msg,deskid){
		
		$(".messager-body").each(function(){
			
			var op =$(this).panel('options'); 
			if(op.title==title)
			{
				$(this).window('close');
			}
		});
		
		

		var url ="showChat?&deskid="+deskid;
		$.messager.show({
			title:title,
			msg:msg+"&nbsp;&nbsp;<a href=\"#\" onclick=\"addPanelHideMsg('"+title+"','"+url+"')\">回复</a>",
			showType:'show',
			timeout:0
		});
	}
	function closeWin() {   
		window.opener=null;   
		window.open('','_self');  
		window.close(); 
	} 

	
	function notify()
	{
		
		
		 
		 var url = "p_getMsgNotifyJson?key="+$("#key").val();
		 $.ajax(
		 			{
		 	        	url: url,
		 	        	async: true,//改为同步方式
		 	        	type: "GET",
		 	        	success: function (json) {
		 	        		
		 	        		var flag = json.flag;
		 	        		
		 	        		if(flag=='0')
		 	        		{
		 	        			closeWin();
		 	        			return;
		 	        		}
		 	        		
		 	        		
		 	        		var areaDetail=json.areaDetail;
		 	        		$('#areacount').html(areaDetail);
		 	        		
		 	        		var msglist = json.deskmsg;
		 	        		
		 	        		
		 	        		if(msglist && msglist.length>0)
		 	        		{
		 	        		
		 	        			
			 	        		 for(i=0;i<msglist.length;i++)
			 	        		 {
			 	        			 var item = msglist[i];
			 	        			 var msg = item.dmsg;
			 	        			 var name=item.idnum+"号桌";
			 	        			 var name1=name+"_有未读消息";
			 	        			 var is = $('#tt').tabs("exists",name);
			 	        			 var is1 = $('#tt').tabs("exists",name1);
			 	        		     if(is==true || is1==true)
			 	        		     {
			 	        		    	var text = $('#tt').tabs('getSelected').panel('options');
			 	        		    	var ttitle=text.title;
			 	        		    	if(is==true && ttitle!=name)
			 	        		    	{
			 	        		    		var ti = name+"_有未读消息";
				 	        		    	var tab = $('#tt').tabs("getTab",name);
				 	        		    	$('#tt').tabs('update', {tab: tab,options: {title: ti}});
			 	        		    	}
			 	        		    	
			 	        		     }else
			 	        		     {
			 	        		    	 showmsg(name,msg,item.deskid);
			 	        		     }
			 	        		    	
			 	        		    
			 	        			
			 	        		 }
		 	        		}
		 	        		
		 	        		
		 	        		
		 	 			}
		 	 	});
		 setTimeout(function(){notify();}, 1000);
	}
	
	
	function logout()
	{
		 $.get("logout", function(data){
			 window.location.href='/';
			});
	}
	
	function addPanelHideMsg(text,url){
		
		var len = $(".messager-body").length;
		var index = len-1;
		var op =$(".messager-body").eq(index).panel('options'); 
		$(".messager-body").eq(index).window('close');
				
		addPanel(text,url);
		
	}
	
	function iframechange(obj)
	{
		
	    if(obj.readyState=='complete')
	    {
	    	gshow--;
	    }
	}
	
	function addTabs(text,url,width,flag)
	{
		var is = $('#tt').tabs("exists",text);
	    
	    var html ='<iframe name="tframe" onreadystatechange="iframechange(this)" style="width:100%;height:100%" frameborder="no" src="'+url+'" ></iframe>';
	    
	    
	    if(is==true)
	    	 var is = $('#tt').tabs("close",text);
	    
		$("#tt").tabs("add",{
			title: text,
			content: html,
			closable: flag
		});
		
	}
	
	function addPanel(text,url){
	    var is = $('#tt').tabs("exists",text);
	    
	    var html ='<iframe name="tframe" style="width:100%;height:100%" frameborder="no" src="'+url+'" ></iframe>';
	    
	    
	    if(is==true)
	    	 var is = $('#tt').tabs("close",text);
	    
		$("#tt").tabs("add",{
			title: text,
			content: html,
			closable: true
		});
		
	}
	
	var timer;
	var index=0;
	function isHide()
	{
		if(index==3)
		{
			clearInterval(timer);
			$.unblockUI();
		}else
		{
			index++;
		}
		
		if(gshow==0)
		{
			clearInterval(timer);
			$.unblockUI();
		}
	}
	
	
	$(document).ready(  
			  function(){
				  
				  setInterval(setLocalTime, 1000);
				  
				  $('body').block( {
						message : '正在加载，请稍候……',
						css: {width:'120px', color:'#fff',border:'1px solid #aaa',backgroundColor:'#CC3300'},
				  		overlayCSS:  {
							backgroundColor:	'#ADADAD',
							cursor:				'progress'
						}
					});
				  
				  timer = setInterval("isHide()",1000);
				  gh=$(window).height();
				  gw=$(window).width();
				  
				  
				  $('#tt').tabs({
					  onSelect:function(title){
						  refresh();
					 		if(title.indexOf("号桌_")>0)
					 		{
					 			
					 			var arr=title.split("_");
	 	        		    	var tab = $('#tt').tabs("getTab",title);
	 	        		    	 $('#tt').tabs('update', {tab: tab,options: {title: arr[0]}});
					 		}
					  }
					  });
				  
				  var url = "loadMenuTree";
				  $.get(url, function(data){
					  var msg = $.parseJSON(data);
					  	
					  	 $('#aa').tree("loadData", msg);
					  	$('#aa').tree({onSelect:function(node){
					  		
					  		if(typeof(node.id) != "undefined")
					  		{
					  			addPanel(node.text,node.id);
					  		}
					  		
					  	}});
					 
					});
					
				 showAreaList();
				  
				  setTimeout(function(){notify();}, 1000);
	 });
	
	function refresh()
	{
		
		var text = $('#tt').tabs('getSelected').panel('options');
	    var ttitle=text.title;
		var surl="";
		for(i=0;i<area.length;i++)
 		{
 			var item = area[i];
 			if(item.areaname==ttitle)
 			{
 				gareaid= item.id;
 				break;
 			}
 		}
		
		return;
		
	}
	
	
	
	function showAreaList()
	{
		$.get("areaList", function(data){
			
				area = data;
				gshow = data.length;
			 	var i;
			 	for(i=0;i<data.length;i++)
			 		{
			 			var item = data[i];
			 			
			 			var url="show_deskdetail?areaid="+item.id;
			 			
			 			addTabs(item.areaname,url,150,false);
			 			
			 		}
			 
			});
	}
	
	function myresize()
	{
		//setTimeout(function(){showAreaList();}, 200);
	}
	
	 function setLocalTime() {
		  $('#dateLable').html(new Date().toLocaleString() + ' 星期' + '日一二三四五六'.charAt(new Date().getDay()));
	 }
	  
	
	/*]]>*/  
	</script>
	
<style type="text/css">
.top{height:5px;line-height:5px;background:#f6f6f6;width:100%;position:fixed;z-index:255;top:79px;text-align:center;}
#header{height:100%;line-height:65px;background:#00a5a5;width:100%;position:absolute;z-index:5;top:0;text-align:center;}
.logo{line-height:65px;font-size:30px;color:#fff; letter-spacing:3px;margin-left:20px;float:left;}
.navigation{float:right;margin:10px 50px 0 0;color:#fff;}
.navigation ul li{height:30px;line-height:30px;text-align:center;float:left;margin-left:15px;list-style-type:none;}
.navigation ul li a{color:#fff;}
.navigation ul li a:hover{color:#32323a;}

.rfloat{position:absolute; right:50px; top:50px;color:#008000;} 
.rfloat ul li{height:30px;line-height:30px;text-align:center;float:left;margin-left:15px;list-style-type:none;}

a:link,a:visited{
 		text-decoration:none;  /*超链接无下划线*/
	}
	a:hover{
 		text-decoration:none;  /*鼠标放上去有下划线*/
	}
	
</style>

</head>
<body class="easyui-layout">
	<div data-options="region:'north',border:false" style="height:12%;background:#B3DFDA;">
		<div id="header">
			<div class="logo">点餐后台管理系统</div>
			<div class="navigation">
				<ul>
					<li><span id="areacount" style="font-size:12px;"></span>
					</li>
					
				</ul>
				
			</div>
			<div class="rfloat">
			<ul>
					<li><span id="dateLable"></span></li>
					<li><a href="#" onclick="logout()" style="color:#008000">退出</a></li>
				</ul>
			</div>
		</div>

	</div>
	<div data-options="region:'west',split:true,title:'系统管理',collapsed:true" style="width:12%;padding:10px;">
		<!-- 左边菜单栏 -->
		<ul  id="aa" class="easyui-tree" data-options="checkbox:false">
			
		</ul>
		
	</div>
	<div id="pp"  data-options="region:'center',onResize:myresize">
		<!-- 内容栏 -->
			<div id="tt" class="easyui-tabs" style="width:100%;height:100%"  data-options="pill:true">
				
			</div>
	</div>
	
	<input  id="key" type="hidden" th:value="${key}" />
</body>
</html>